package com.base.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 对密码做处理的工具类
 * 
 * @author Administrator
 *
 */
public class PasswordUtils {
	public static String CUS = "CustomBase64";

	/**
	 * 解码并判断输入密码是否正确
	 * 
	 * @param enter
	 * @param base64code
	 * @return
	 */
	public static boolean decodePWD(String enter, String base64code) {
		String realcode = Base64Util.decodeData(base64code);
		if (realcode.contains(CUS)) {
			realcode = realcode.substring(0, realcode.length() - 12);
            return enter.equals(realcode);
		} else {
            return enter.equals(realcode);
		}
	}

	/**
	 * 查看解码后的密码文本
	 * 
	 * @param base64code
	 * @return
	 */
	public static String decodePWD(String base64code) {
		String realcode = Base64Util.decodeData(base64code);
		if (realcode.contains(CUS)) {
			realcode = realcode.substring(0, realcode.length() - 12);
		}
		return realcode;
	}

	/**
	 * 加密
	 * 
	 * @param password
	 * @return
	 */
	public static String toPWD(String password) {
		if (password == null) {
			return null;
		}
		return Base64Util.encodeData(password + CUS);
	}

	/**
	 * 获取现在时间
	 * 
	 * @return返回字符串格式yyyyMMddHHmmss
	 */
	public static String getStringDate() {
		Date currentTime = new Date();
		SimpleDateFormat formatter = new SimpleDateFormat("yyMMddHH");
		String dateString = formatter.format(currentTime);
		System.out.println("TIME:::" + dateString);
		return dateString;
	}

	/**
	 * 由年月日时分秒+3位随机数 生成流水号
	 * 
	 * @return
	 */
	public static String Getnum() {
		String t = getStringDate();
		int x = (int) (Math.random() * 900) + 100;
		String serial = t + x;
		return serial;
	}

	public static void main(String[] args) {
		// System.out.println("解码：" +
		// decodePWD("ODQ2MTM4NjY=Q3VzdG9tQmFzZTY0"));

		String m = Getnum();
		System.out.println(Produce.getUUID().substring(9, 12) + System.currentTimeMillis());
	}
}
